package com.ruoyi.factory.qylock.controller.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.factory.common.utils.RequestUtil;
import com.ruoyi.factory.qylock.service.QysLaborService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * @ClassName QysLaborController
 * @Description: TODO 人力劳动合同 保密协议 集成契约锁
 * @Author LiuJiaji
 * @Date 2023/11/3 09:50
 **/
@EnableScheduling
@RestController("qysLaborController")
@RequestMapping("/api/qysLabor")
public class QysLaborController {

    @Autowired
    private QysLaborService qysLaborService;

    /**
     * @author: Liujiaji
     * @date: 2023/11/14 09:45
     * @description: TODO 人力合同签署处理
     * @param: [type, orgid, termtype] 流程类型, 组织id, 合同期限类型
     * @return: void
     **/
    public void laborContracthand(String type){
        // 1.查询昨天 签署状态为非签署中和签署完成的人  2.调用契约锁进行签署
        qysLaborService.laborContracthand(type);
        //保密协议自动签署业务
        qysLaborService.secreContracthand(type);
//      劳动合同重推sql 修改数据之后执行重推定时任务
//        select  hiph.conttype contratype, hiph.contractnum contracode, hiph.pk_psndoc_sub contraid, hiph.signdate signdate, hiph.creationtime creationtime,
//        hiph.termtype termtype,
//        hiph.glbdef1 glbdef1, hiph.glbdef2 glbdef2, hiph.begindate begindate, hiph.enddate enddate,
//        hiph.probegindate probegindate, hiph.probenddate probenddate, hiph.promonth promonth, hiph.prop_unit propunit, hiph.signaddr signaddr,
//        hiph.glbdef3 atfist ,to_char(TO_DATE(hiph.creationtime, 'yyyy-mm-dd hh24:mi:ss'), 'YYYY-MM-DD') createdate,
//                bdph.name yf_name, (case when bdph.sex = '1' then '男' when bdph.sex = '2' then '女' else '' end) sex, bdph.id card_id, bdph.censusaddr censusaddr, bdph.mobile phonenum,
//                bdpsh.name zj_name,
//                bddh.name mz_name,
//                (case when orgh.pk_adminorg = '0001A110000000002TL4' then '0001A110000000002TJA' else orgh.pk_adminorg end) orgid,
//                (case when orgh.name = '萱润（上海）化工科技有限公司' then '新乡市瑞丰新材料股份有限公司' else orgh.name end) orghname,
//                wav.levelname waprmlvxq,
//                omjoh.name waprmlv,
//                defh.code work_class,
//                defh2.code work_rule
//        from hi_psndoc_ctrt hiph
//        left join bd_psndoc bdph on hiph.pk_psndoc = bdph.pk_psndoc and bdph.dr=0
//        left join bd_defdoc bddh on bdph.nationality = bddh.pk_defdoc and bddh.dr=0
//        left join bd_psnidtype bdpsh on bdpsh.pk_identitype = bdph.idtype and bdpsh.dr=0
//        left join org_adminorg orgh on hiph.pk_org = orgh.pk_adminorg and orgh.dr=0
//        left join bd_defdoc defh on hiph.glbdef4 = defh.pk_defdoc and defh.dr=0
//        left join bd_defdoc defh2 on hiph.glbdef5 = defh2.pk_defdoc and defh2.dr=0
//        left join hi_psndoc_wadoc hic on bdph.pk_psndoc =  hic.pk_psndoc and hic.dr=0 AND hic.waflag='Y' AND hic.lastflag='Y' AND hic.pk_wa_item ='1001A110000000012VBZ'
//        left join wa_prmlv wav on hic.pk_wa_prmlv = wav.pk_wa_prmlv  and wav.dr=0
//        left join hi_psnjob hpsh on hiph.pk_psnjob=hpsh.pk_psnjob and hpsh.dr=0 and hpsh.ismainjob='Y' and hpsh.lastflag='Y' and hpsh.enddate is null
//        left join om_joblevel omjoh on hpsh.pk_jobgrade =omjoh.pk_joblevel and omjoh.dr=0
//        where
//        hiph.dr=0
//        and bdph.name = '苗素媛'
//        and to_char(TO_DATE(hiph.creationtime, 'yyyy-mm-dd hh24:mi:ss'), 'YYYY-MM-DD') = '2024-02-20'
//        and hiph.pk_psndoc_sub = '1001A9100000003WTRLM'
//        and hiph.conttype = '2'
//        select * from hi_psndoc_ctrt where pk_psndoc_sub = '1001A9100000003WTRLM'
//        update hi_psndoc_ctrt set glbdef1 = '',creationtime='2024-02-27 08:56:01' where pk_psndoc_sub = '1001A9100000003WTRLM'
//        update hi_psndoc_ctrt set creationtime='2024-02-20 08:56:01' where pk_psndoc_sub = '1001A9100000003WTRLM'

        //保密协议

//        select hrch.contcode contracode, hrch.pk_agreement contraid,
//        (case when hrch.pk_org = '0001A110000000002TL4' then '0001A110000000002TJA' else hrch.pk_org end) orgid,
//                hrch.creationtime creationtime, hrch.signdate signdate, hrch.begindate begindate, hrch.enddate enddate, hrch.agreedef1 glbdef1, hrch.agreedef2 glbdef2,
//                to_char(TO_DATE(hrch.creationtime, 'yyyy-mm-dd hh24:mi:ss'), 'YYYY-MM-DD') createdate,
//                bdph.name yf_name, bdph.id card_id,  bdph.censusaddr censusaddr, bdph.mobile phonenum,
//                bdpsh.name zj_name,
//                (case when orgh.name = '萱润（上海）化工科技有限公司' then '新乡市瑞丰新材料股份有限公司' else orgh.name end) orghname
//        from hrcm_agreement hrch
//        left join bd_psndoc bdph on hrch.pk_psndoc = bdph.pk_psndoc and bdph.dr=0
//        left join bd_psnidtype bdpsh on bdpsh.pk_identitype = bdph.idtype and bdpsh.dr=0
//        left join org_adminorg orgh on hrch.pk_org = orgh.pk_adminorg and orgh.dr=0
//        where
//        hrch.dr=0
//        and bdph.name  = '赵森森'
//        select * from  hrcm_agreement where pk_agreement = '1001A9100000004H5MKQ'
//        update hrcm_agreement set agreedef1 = '',creationtime='2024-05-05 10:50:13' where pk_agreement = '1001A9100000004H5MKQ'
//        update hrcm_agreement set creationtime='2024-04-28 10:50:13' where pk_psndoc_sub = '1001A9100000004H5MKQ'
    }

    /**
     * @author: Liujiaji
     * @date: 2023/6/6 0006 17:37
     * @description: TODO 契约锁回调处理
     * @param: [prejson]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/upStatusNotify")
    public AjaxResult upStatus(HttpServletRequest request){
        Map<String, String> notifyResult = RequestUtil.getRequestParams(request);
        return qysLaborService.upStatus(notifyResult);
    }

    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        long time = new Date().getTime();
        System.out.println(l+"---"+time);
        String s = "123456789";
        String substring = s.substring(0, 2);
        String substring2 = s.substring(2, 5);
        System.out.println(substring);
        System.out.println(substring2);
        String ss = "2023-11-14";
        System.out.println(ss.substring(0,4));
        System.out.println(ss.substring(5,7));
        System.out.println(ss.substring(8,10));
    }
}
